public class NextDate {
    //判断是否为闰年
    static private boolean isLeapYear(int year) {
        boolean isLeapYear = false;
        if (year % 4 == 0) {
            if (year % 100 == 0) {
                if (year % 400 == 0) {
                    isLeapYear = true;
                }
            } else
                isLeapYear = true;
        }

        return isLeapYear;
    }

    static public String nextDate(int year, int month, int day) {
        //如果输入参数不合法，返回null
        if (year <= 0 || month < 1 || month > 12 || day < 1 || day > 31)
            return null;

        int nyear = year;
        int nmonth = month;
        int nday = day;

        switch (month) {
            case 1:
            case 3:
            case 7:
            case 8:
            case 10:
                //正常31天的月份
                if (day < 31)
                    nday = day + 1;
                else {
                    nday = 1;
                    nmonth = month + 1;
                }
                break;
            case 4:
            case 6:
            case 9:
            case 11:
                //正常30天的日子
                if (day < 30)
                    nday = day + 1;
                else {
                    nday = 1;
                    nmonth = month + 1;
                }
                break;
            case 2:
                //2月份单独处理
                if (day <= 28) {
                    if (isLeapYear(year))
                        nday = 29;
                    else {
                        nday = 1;
                        nmonth = month + 1;
                    }
                }
                else if (day == 29) {//此处未考虑输入平年29号错误，看是否能够测试出来
                    if(isLeapYear(year)) {
                        nday = 1;
                        nmonth = month + 1;
                    }
                    else
                        return null;
                }
                else {
                    return null;
                }

                break;
            case 12:
                //12月份单独处理
                if (day < 31)
                    nday = day + 1;
                else {
                    nday = 1;
                    nmonth = 1;
                    nyear = year + 1;
                }

                break;
            default:
                return null;
        }

        return String.format("%d-%d-%d", nyear, nmonth, nday);
    }
}
